﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using SmallShop.BaseWeb;
using SmallShop.Bll;
using SmallShop.Frame;
using SmalShop.Model;

namespace SmallShop.ManagerWeb.Controllers
{
    /// <summary>
    /// 产品类型
    /// </summary>
    public class CategoryController : SmallController
    {
        private CategoryBiz _categoryBiz;
        public CategoryController()
        {
            _categoryBiz = new CategoryBiz();
        }

        // GET: Categroy
        public ActionResult Index()
        {
            return View();
        }


        public ActionResult All(int page = 1, int limit = 10)
        {
            var query = _categoryBiz.Query();
            var count = query.Count();
            var rows = query.OrderByDescending(it=>it.Id).Skip((page - 1)*limit).Take(limit);
            return Json(new ResultModel {Data = new { count, rows}});
        }

        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="m"></param>
        /// <returns></returns>
        public ActionResult Add(CategoryModel m)
        {
            return Json(_categoryBiz.Add(m));
        }
        
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="m"></param>
        /// <returns></returns>
        public ActionResult Update(CategoryModel m)
        {
            return Json(_categoryBiz.Update(m));
        }



        /// <summary>
        /// 简单信息
        /// </summary>
        /// <returns></returns>
        public ActionResult List()
        {
            var all = _categoryBiz.Query();
            return Json(all.Select(it => new {it.Id, it.Title}));
        }
    }
}